package cn.meizhu.base.controller;

import cn.meizhu.util.AjaxResult;
import cn.meizhu.util.FastDfsUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/dfs")
public class FastDfsController {

    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file){

        String filename = file.getOriginalFilename();
        String substring = filename.substring(filename.indexOf(".") + 1);
        try {
            String upload = FastDfsUtil.upload(file.getBytes(), substring);
            System.out.println(upload);
            return AjaxResult.me().setResultObj(upload);
        } catch (IOException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }


}
